package cn.volunteer.points.system.handle;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.util.HashMap;
import java.util.Map;

/**
 * @description: 请输入描述信息
 * @author: chenxiaofeng
 * @create: 创建时间：2021-05-10
 **/
@ControllerAdvice
public class ControllerHanderException {
    @ExceptionHandler(ServiceException.class)
    @ResponseBody
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    //在这个方法里定义我们需要返回的格式
    public Map<String, Object> handleUserNotExistException(ServiceException ex){
        Map<String, Object> result = new HashMap<>();
        result.put("code", ex.getCode());  //获取到我们定义的code
        result.put("msg", ex.getMessage());		//获取到我们定义的msg
        return result;
    }

}

